/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;

import DBH.DBHelper;
import com.sun.org.glassfish.external.statistics.Statistic;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JOptionPane;

/**
 *
 * @author Cun_con_yeu_em
 */
public class sanpham {

    private DBHelper obj = new DBHelper();
    private Vector v;
    private String idsp;
    private String ten;
    private String giatien;
    private int soluong;
    private String loai;

    public sanpham() {
    }

    public sanpham(String idsp, String ten, String giatien, int soluong, String loai) {
        this.idsp = idsp;
        this.ten = ten;
        this.giatien = giatien;
        this.soluong = soluong;
        this.loai = loai;

    }

    // Khong co tham so
    public Vector getAllsanpham() throws SQLException {

        Vector v = new Vector();
        try {
            ResultSet rs = getObj().executeQuery("sp_getAllsanpham");
            while (rs.next()) {
                sanpham s = new sanpham();
                s.setIdsp(rs.getString(1));
                s.setTen(rs.getString(2));
                s.setGiatien(rs.getString(3));
                s.setSoluong(rs.getInt(4));
                s.setLoai(rs.getString(5));
                v.add(s);

            }
        } catch (SQLException sqle) {
        }
        return v;
    }

    // Idsp
    public Vector getAlidsp() throws SQLException {

        Vector v = new Vector();
        try {
            ResultSet rs = getObj().executeQuery("sp_Ddhidsp");
            while (rs.next()) {
                sanpham s = new sanpham();
                s.setIdsp(rs.getString(1));
                v.add(s);
            }
        } catch (SQLException sqle) {
        }
        return v;
    }
    // Co tham so

    public Vector getSanphaml1(String name) throws SQLException {

        Vector v = new Vector();
        Vector paramList = new Vector();
        paramList.add(name);
        try {
            ResultSet rs = DBHelper.executeQuery("sp_getSanphaml1", paramList);
            while (rs.next()) {
                sanpham s = new sanpham();
                s.setIdsp(rs.getString(1));
                s.setTen(rs.getString(2));
                s.setGiatien(rs.getString(3));
                s.setSoluong(rs.getInt(4));
                s.setLoai(rs.getString(5));
                v.add(s);

            }
        } catch (SQLException sqle) {
        }
        return v;
    }
 public Vector searchid(String id1) throws SQLException {

        Vector v = new Vector();
        Vector paramList = new Vector();
        paramList.add(id1);
        try {
            ResultSet rs = DBHelper.executeQuery("sp_searchSanphamid", paramList);
            while (rs.next()) {
                sanpham s = new sanpham();
                s.setIdsp(rs.getString(1));
                s.setTen(rs.getString(2));
                s.setGiatien(rs.getString(3));
                s.setSoluong(rs.getInt(4));
                s.setLoai(rs.getString(5));
                v.add(s);

            }
        } catch (SQLException sqle) {
        }
        return v;
 }
    //san pham loai 2
    public Vector getSanphaml2(String name) throws SQLException {

        Vector v = new Vector();
        Vector paramList = new Vector();
        paramList.add(name);
        try {
            ResultSet rs = DBHelper.executeQuery("sp_getSanphaml2", paramList);
            while (rs.next()) {
                sanpham s = new sanpham();
                s.setIdsp(rs.getString(1));
                s.setTen(rs.getString(2));
                s.setGiatien(rs.getString(3));
                s.setSoluong(rs.getInt(4));
                s.setLoai(rs.getString(5));
                v.add(s);

            }
        } catch (SQLException sqle) {
        }
        return v;
    }

    //San pham loai 3
    public Vector getSanphaml3(String name) throws SQLException {

        Vector v = new Vector();
        Vector paramList = new Vector();
        paramList.add(name);
        try {
            ResultSet rs = DBHelper.executeQuery("sp_getSanphaml3", paramList);
            while (rs.next()) {
                sanpham s = new sanpham();
                s.setIdsp(rs.getString(1));
                s.setTen(rs.getString(2));
                s.setGiatien(rs.getString(3));
                s.setSoluong(rs.getInt(4));
                s.setLoai(rs.getString(5));
                v.add(s);

            }
        } catch (SQLException sqle) {
        }
        return v;
    }

    // San pham Khac
    public Vector getSanphaml4(String name) throws SQLException {

        Vector v = new Vector();
        Vector paramList = new Vector();
        paramList.add(name);
        try {
            ResultSet rs = DBHelper.executeQuery("sp_getSanphaml4", paramList);
            while (rs.next()) {
                sanpham s = new sanpham();
                s.setIdsp(rs.getString(1));
                s.setTen(rs.getString(2));
                s.setGiatien(rs.getString(3));
                s.setSoluong(rs.getInt(4));
                s.setLoai(rs.getString(5));
                v.add(s);

            }
        } catch (SQLException sqle) {
        }
        return v;
    }

    public int updatedelete(sanpham s) throws SQLException {
        int i = 0;
        try {
            Vector paramList = new Vector();
            paramList.add(s.getIdsp());
            paramList.add(s.getSoluong());
            i = DBHelper.executeUpdate("sp_Updatexoa", paramList);
        } catch (SQLException sqlex) {
        }
        return i;

    }

    public Vector search(String name) throws SQLException {

        Vector v = new Vector();
        Vector paramList = new Vector();
        paramList.add(name);
        try {
            ResultSet rs = DBHelper.executeQuery("sp_searchSanpham", paramList);
            while (rs.next()) {
                sanpham s = new sanpham();
                s.setIdsp(rs.getString(1));
                s.setTen(rs.getString(2));
                s.setGiatien(rs.getString(3));
                s.setSoluong(rs.getInt(4));
                s.setLoai(rs.getString(5));
                v.add(s);

            }
        } catch (SQLException sqle) {
        }
        return v;
    }

    public Vector timkiem1(String name) throws SQLException {

        Vector v = new Vector();
        Vector paramList = new Vector();
        paramList.add(name);
        try {
            ResultSet rs = DBHelper.executeQuery("sp_Spgiatien", paramList);
            while (rs.next()) {
                sanpham s = new sanpham();
                s.setIdsp(rs.getString(1));
                s.setTen(rs.getString(2));
                s.setGiatien(rs.getString(3));
                s.setSoluong(rs.getInt(4));
                s.setLoai(rs.getString(5));
                v.add(s);

            }
        } catch (SQLException sqle) {
        }
        return v;
    }

    public int insertSanpham(sanpham s) throws SQLException {
        int i = 0;
        try {
            Vector paramList = new Vector();
            paramList.add(s.getIdsp());
            paramList.add(s.getTen());
            paramList.add(s.getGiatien());
            paramList.add(s.getSoluong());
            paramList.add(s.getLoai());
            i = DBHelper.executeUpdate("sp_insertSanpham", paramList);
        } catch (SQLException sqlex) {
        }
        return i;
    }

    public int updateSanpham(sanpham s) throws SQLException {
        int i = 0;
        try {
            Vector paramList = new Vector();
            paramList.add(s.getIdsp());
            paramList.add(s.getTen());
            paramList.add(s.getGiatien());
            paramList.add(s.getSoluong());
            paramList.add(s.getLoai());
            i = DBHelper.executeUpdate("sp_updateSanpham", paramList);
        } catch (SQLException sqlex) {
        }
        return i;
    }

    public int deleteSanpham(String idsp) throws SQLException {
        int i = 0;
        try {
            Vector paramList = new Vector();
            paramList.add(idsp);
            i = DBHelper.executeUpdate("sp_deleteSanpham", paramList);
        } catch (SQLException sqlex) {
        }
        return i;
    }

    /**
     * @return the obj
     */
    public DBHelper getObj() {
        return obj;
    }

    /**
     * @param obj the obj to set
     */
    public void setObj(DBHelper obj) {
        this.obj = obj;
    }

    /**
     * @return the v
     */
    public Vector getV() {
        return v;
    }

    /**
     * @param v the v to set
     */
    public void setV(Vector v) {
        this.v = v;
    }

    /**
     * @return the idsp
     */
    public String getIdsp() {
        return idsp;
    }

    /**
     * @param idsp the idsp to set
     */
    public void setIdsp(String idsp) {
        this.idsp = idsp;
    }

    /**
     * @return the ten
     */
    public String getTen() {
        return ten;
    }

    /**
     * @param ten the ten to set
     */
    public void setTen(String ten) {
        this.ten = ten;
    }

    /**
     * @return the giatien
     */
    public String getGiatien() {
        return giatien;
    }

    /**
     * @param giatien the giatien to set
     */
    public void setGiatien(String giatien) {
        this.giatien = giatien;
    }

    /**
     * @return the soluong
     */
    public int getSoluong() {
        return soluong;
    }

    /**
     * @param soluong the soluong to set
     */
    public void setSoluong(int soluong) {
        this.soluong = soluong;
    }

    /**
     * @return the loai
     */
    public String getLoai() {
        return loai;
    }

    /**
     * @param loai the loai to set
     */
    public void setLoai(String loai) {
        this.loai = loai;
    }
}
